﻿/*********************************************************************************
**                                                                              **
**  Copyright (C) 2024 LiLong                                                   **
**  This file is part of GnssLogs.                                              **
**                                                                              **
**  GnssLogs is free software: you can redistribute it and/or modify            **
**  it under the terms of the GNU Lesser General Public License as published by **
**  the Free Software Foundation, either version 3 of the License, or           **
**  (at your option) any later version.                                         **
**                                                                              **
**  GnssLogs is distributed in the hope that it will be useful,                 **
**  but WITHOUT ANY WARRANTY; without even the implied warranty of              **
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               **
**  GNU Lesser General Public License for more details.                         **
**                                                                              **
**  You should have received a copy of the GNU Lesser General Public License    **
**  along with GnssLogs.  If not, see <https://www.gnu.org/licenses/>.          **
**********************************************************************************/
#pragma once

#include "../BESTVEL.h"
#include "LogHeaderDecoder.h"

namespace GnssLogs
{
namespace BESTVELDecoder
{
using namespace tao::pegtl;
using Sync   = TAO_PEGTL_STRING("#BESTVELA");
using Header = LogHeaderDecoder::SyncExpression<Sync>;
// clang-format off
struct SolStatus : ascii::identifier {};
struct VelType : ascii::identifier {};
struct Latency : Floating {};
struct Age : Floating {};
struct HorSpd : Floating {};
struct TrkGnd : Floating {};
struct VertSpd : Floating {};
struct Reserved : Floating {};
// clang-format on

using Expression = seq<Header,
                       SolStatus,
                       Split,
                       VelType,
                       Split,
                       Latency,
                       Split,
                       Age,
                       Split,
                       HorSpd,
                       Split,
                       TrkGnd,
                       Split,
                       VertSpd,
                       Split,
                       Reserved,
                       one<'*'>,
                       CRC32>;

template<typename T>
struct Action
{
};

template<>
struct Action<Header> : LogHeaderDecoder::LogHeaderHelperNoSetValue
{
};

template<>
struct Action<SolStatus> : EnumHelper<Action<SolStatus>, SolutionStatus>
{
    static void setValue(BESTVEL::Data& data, SolutionStatus value) { data.solStatus = value; }
};

template<>
struct Action<VelType> : EnumHelper<Action<VelType>, PositionOrVelocityType>
{
    static void setValue(BESTVEL::Data& data, PositionOrVelocityType value) { data.velType = value; }
};

template<>
struct Action<Latency> : FloatHelper<Action<Latency>>
{
    static void setValue(BESTVEL::Data& data, float value) { data.latency = value; }
};

template<>
struct Action<Age> : FloatHelper<Action<Age>>
{
    static void setValue(BESTVEL::Data& data, float value) { data.age = value; }
};

template<>
struct Action<HorSpd> : DoubleHelper<Action<HorSpd>>
{
    static void setValue(BESTVEL::Data& data, double value) { data.horSpd = value; }
};

template<>
struct Action<TrkGnd> : DoubleHelper<Action<TrkGnd>>
{
    static void setValue(BESTVEL::Data& data, double value) { data.trkGnd = value; }
};

template<>
struct Action<VertSpd> : DoubleHelper<Action<VertSpd>>
{
    static void setValue(BESTVEL::Data& data, double value) { data.vertSpd = value; }
};

template<>
struct Action<Reserved> : FloatHelper<Action<Reserved>>
{
    static void setValue(BESTVEL::Data& data, float value) { data.reserved = value; }
};

template<>
struct Action<CRC32> : CRC32Helper<Action<CRC32>>
{
    static void setValue(BESTVEL::Data& data, uint32_t value) { data.crc32 = value; }
};
} // namespace BESTVELDecoder
} // namespace GnssLogs